<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;

//个人中心控制器
class CenterController extends Controller{
	private $model;
	private $indentList;
	public function __init(){
	   	//订单表
	    $this->model = new \Common\Model\indent;
		//订单列表
	    $this->indentList = new \Common\Model\indentList;
	}
    //默认
    public function index(){
    	//获得$_SESSION里面的uid
    	$uid = $_SESSION['uid'];
    	//获得订单
		$data = $this->model->where("in_uid={$uid}")->get();
		foreach ($data as $k => $v) {
			//在商品列表找到商品表id
			$gid = Db::table('indent_list')->where("il_iid={$v['inid']}")->pluck('il_gid');
			$data[$k]['list'] = Db::table('indent_list')->join('shop_goods','gid','=','il_gid')->where("il_iid={$v['inid']}")->get();
		}
		View::with('data',$data);
		//获得未付款的订单数量
		$num = $this->model->where("in_status=0 AND in_uid={$uid}")->count();
		View::with('num',$num);
		//订单总数量
		$amount = count($data);
		View::with('amount',$amount);
		//载入模板
		View::make();
    }
	
	//取消订单
	public function undo(){
	    $inid = Q('get.inid',0,'intval');
		$this->model->where("inid={$inid}")->save(array('in_status'=>5));
		View::success('撤销订单成功',U('index'));
	}
	
	//删除订单
	public function del(){
		$inid = Q('get.inid',0,'intval');
		//删除对应数据
		$this->model->where("inid={$inid}")->delete();
		$this->indentList->where("il_iid={$inid}")->delete();
		//成功提示
		View::success('删除成功',U('Center/index'));
	}
}